<?php
namespace app\teacher\controller;
use app\teacher\model\User;
use app\teacher\model\Video;
use app\teacher\model\Videotype;
use app\teacher\model\Apply;
use app\teacher\model\Teacher;
use think\Request;
use think\Session;
class  Videos extends Base
{
    public function index(){
        $data = array(
            "videotype"=> Videotype::where(['status'=>1])->order("sort","asc")->select(),
            "setting" => $this->getAllSetting(),
        );
        return view("index",$data);
    }
    // 视频列表
    public function videolist(Request $request){
      $data = [
        "setting" => $this->getAllSetting(),
        "videotype_name"=>Videotype::where(["id"=>$request->get("videotype")])->field("name")->find(),
        "video" => Video::where(["status"=>1,"videotype"=>$request->get("videotype")])->order("sort","asc")->paginate(15,true,['query'=>request()->param()]),
      ];
      return view("videolist",$data);
    }
    // 视频播放页面
    public function detail(Request $request){
      $user = $this->user_info2();
      $Applys = collection(Apply::where(array("userid"=>$user['id']))->select())->toArray();
      $teacher = "";
      if($Applys) {
        $index = count($Applys) - 1;
        $teacher = $Applys[$index]['teacher_id'] != null ? Teacher::get($Applys[$index]['teacher_id'])->toArray() : null;
      }
      $id =  !empty($request->route("id")) ? $request->route("id") : false;
      $data = [
        "setting"=>$this->getAllSetting(),
        "video" => Video::get($id),
        "videolist" => Video::order("id","desc")->limit(0,5)->select(),
        "qrcode" => $this->getSetting("teacher_qrcode"),
        "teacher" => $teacher
      ];
      return view("detail",$data);
    }

}
